<?php 
function GetManufacturers()
{
        $conn = getConnection();
        $result = $conn->query('SELECT * FROM EcsManufacturers M');
        return $result;
}

function GetAddress($id)
{
        $conn = getConnection();
        $result = $conn->query("SELECT * FROM EcsManufacturers M WHERE ID=$id");
        $rs = $result->fetch_assoc();
        $conn->close();
        return $rs;
}

function SaveManufacturer($rs)
{ 
		$conn = getConnection();
		$rs = RsEscape($conn, $rs);
        $result = $conn->query("UPDATE EcsManufacturers Man SET Manufacturer='$rs[Manufacturer]', Updated_at=NOW(), WHERE ID=$rs[ID]");     
        $error = $conn->error;
        $conn->close();
        return $error ? array('Server Error'=> $error) : Null;
        
}

function ValidateManufacturer($rs)
{ 
	$errors = Null;
	if(empty($rs['Manufacturer']))
	{
		$errors['Manufacturer'] = 'A Manufacturer name is required.';
	}
		
	return $errors;
	
}

function DeleteManufacturer($id)
{
	
		$conn = getConnection();
        $result = $conn->query("DELETE FROM EcsManufacturers WHERE ID=$id");     
        $error = $conn->error;
        $conn->close();
		return $error ? array('Server Error'=> $error) : Null;
	
}

function AddManufacturers($rs)
{
		$conn = getConnection();
		$rs = RsEscape($conn, $rs);
		$sql = "INSERT INTO EcsManufacturers" 
			   ."(Manufacturer, Created_at)"
			   ."VALUES ('$rs[Manufacturer]', Now())";
        $result = $conn->query($sql);     
        $error = $conn->error;
        $conn->close();
		return $error ? array('Server Error'=> $error) : Null;
	
}

function NewManufacturer()
{
	return array('Manufacturer'=>'', 'Created_at'=>Null, 'Updated_at'=>Null);
}

?>
